using System;
using System.Collections.Generic;
using System.Text;

namespace XProject.Util
{
    class CalendarCalulator
    {
        public static int GetDayOfWeek(DateTime date)
        {
            DayOfWeek dayname = date.DayOfWeek;
            int dayPos=-1;
            switch (dayname)
            {
                case DayOfWeek.Sunday: dayPos= 0; break;
                case DayOfWeek.Monday: dayPos = 1; break;
                case DayOfWeek.Tuesday: dayPos = 2; break;
                case DayOfWeek.Wednesday: dayPos = 3; break;
                case DayOfWeek.Thursday: dayPos = 4; break;
                case DayOfWeek.Friday: dayPos = 5; break;
                case DayOfWeek.Saturday: dayPos = 6; break;
            }
            return dayPos;
        }
        public static DateTime GetFisrtDayOfWeek(DateTime date)
        {
            return new DateTime(date.Year,date.Month,date.Day,0,0,0).AddDays(-GetDayOfWeek(date));
        }
        public static DateTime GetLastDayOfWeek(DateTime date)
        {
            return new DateTime(date.Year,date.Month,date.Day,23,59,59).AddDays(6-GetDayOfWeek(date));
        }
        public static DateTime GetFirstDayOfMonth(DateTime date){
            return new DateTime(date.Year,date.Month,date.Day,0,0,0).AddDays(1-date.Day);
        }
        public static DateTime GetLastDayOfMonth(DateTime date)
        {
            return new DateTime(date.Year,date.Month+1,1,23,59,59).AddDays(-1);
        }
        
    }
}
